const path = require('path');
const glob = require('glob');
// const jquery = require('jquery');
var es3ifyPlugin = require('es3ify-webpack-plugin');
require('object-defineproperty-ie8'); 
const webpack = require('webpack')

// 192.168.120.112  ctr + c  退出热更新服务
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const htmlWebpackPlugin = require("html-webpack-plugin");
// const purifyCssPlugin = require("purifycss-webpack");


// var publicPath = './'  //交付路径
var publicPath ='http://192.168.130.85:3317/'   //开发路径
var webSit = {
    publicPath: publicPath
};
module.exports = {
    devtool:'source-map',
    entry:{
        'index':['object-defineproperty-ie8','./src/index.js'],
        'login':['object-defineproperty-ie8','./src/js/login.js'],
    },
    output:{
        path:path.resolve(__dirname, 'build'),
        filename:'[name].js',
        publicPath:webSit.publicPath
    },
    module:{
        rules:[
            {
                test:/\.css$/i,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {loader:'css-loader', options:{importLoaders:1}},
                        // {loader:'postcss-loader'}
                    ],
                    publicPath: '../../'
                })
            },
            {
              // 图片文件转换
              test:/\.(png|jpg|gif|jpeg)$/,
              use:[
                  {
                      loader: 'file-loader',
                      options: {
                        name: '[name].[ext]',
                        outputPath: 'img/'
                      }
                  }
              ]
            },{
                test:/\.(htm|html)$/i,
                use:['html-withimg-loader']
            },{
                test:/\.less$/,
                use:ExtractTextPlugin.extract({
                    use:[{
                        loader:'css-loader'
                    },{
                        loader:'less-loader'
                    }],
                    fallback:'style-loader'
                })
            },{
                test:/\.scss/,
                use:ExtractTextPlugin.extract({
                    use:[{
                        loader:'css-loader'
                    },{
                        loader:'sass-loader'
                    }],
                    fallback:'style-loader'
                })
            },{
                test:/\.js$/,
                loader:'babel-loader',
                exclude:/node_modules/,
                query: {
                    presets: [['es2015',{
                        "loose" : true,//解决Object.defineProperty
                        "modules" : false
                      }]]
                  }  

                
            }//,
            // {
            //   // 图片文件转换
            //   test:/\.(png|jpg|gif)$/,
            //   loader:'file-loader?name=../img/[name].[ext]'
            // }
        ]
    },
    plugins:[
        // new uglify(),
        new es3ifyPlugin(),
        // new UglifyJsPlugin({uglifyOptions: {ie8: true}}),
        new ExtractTextPlugin('css/[name].css'),
        new htmlWebpackPlugin({
            hash:true,
            template:'./src/index.html'
        }),
        new htmlWebpackPlugin({
            filename: 'login.html',
            template: './src/login.html',
            hash: true,
            chunks:['login'],
            minify: {
                removeAttributeQuotes:true,
                removeComments: true,
                collapseWhitespace: true,
                removeScriptTypeAttributes:true,
                removeStyleLinkTypeAttributes:true
            }
        }),
        new webpack.HotModuleReplacementPlugin(),
    ],
    devServer:{
        contentBase:path.resolve(__dirname, 'build'),
        host:'192.168.130.85',
        compress:true,
        hot: true,
        inline:true,
        port:3317
    }
}
